<?php

namespace App\Admin\Controllers;

use App\Admin\Extensions\OrderExporter;
use App\Services\Models\Orders;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class OrderController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '订单支付单';
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Orders());
        $grid->disableCreateButton();
        $grid->disableFilter();
        //$grid->disableExport();
        $grid->exporter(new OrderExporter());

        $grid->actions(function ($actions) {
            
            // 去掉删除
            $actions->disableDelete();
            // 去掉编辑
            $actions->disableEdit();
            
            // 去掉查看
           // $actions->disableView();
        });
        $grid->model()->where('is_delete',0)->orderBy('id', 'desc');
        $grid->column('id', __('ID'))->sortable();
        $grid->column('tid','订单号');
        $grid->column('goods_name','商品名');
        $grid->column('transaction','有赞支付流水号');
        $grid->column('declare_customs_no','支付报关单号');
        $grid->column('customs_status','推送状态')->display(function($customs_status){
            return Orders::customs_status_text[$customs_status];
        });
        $grid->column('receiver_name', '收货人姓名');
        $grid->column('outer_item_id','备案料号')->editable();
        $grid->column('logistics_no','物流编号')->editable();
        
        $grid->column('pay_time', '支付时间');
        $grid->column('created_at', '创建时间');
        $grid->column('updated_at', '更新时间');

        $grid->column('msg','错误信息')->display(function($msg){
            return empty($msg)?'无':$msg;
        });

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed   $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Orders::findOrFail($id));
        $show->field('tid','订单号');
        $show->field('goods_name','商品名');
        $show->field('created_at', '创建时间');
        $show->field('updated_at', '更新时间');

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Orders());

        $form->display('id', __('ID'));
        $form->display('created_at', __('Created At'));
        $form->display('updated_at', __('Updated At'));

        return $form;
    }
}
